package com.tobeing.voicechat.views;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.tobeing.voicechat.R;

/**
 * Created by Administrator on 2017/10/31/031.
 */

public class RecorderDialog extends Dialog {
    private ImageView mIVIcon;
    private ImageView mIVVoiceLevel;
    private TextView mTVLabel;

    public RecorderDialog(@NonNull Context context) {
        this(context, R.style.RecorderDialogTheme);
    }

    public RecorderDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_recorder, null, false);
        setContentView(view);
        mIVIcon = findViewById(R.id.iv_icon);
        mIVVoiceLevel = findViewById(R.id.iv_voice_level);
        mTVLabel = findViewById(R.id.tv_label);
    }

    public void recording(){
        if(isShowing()){
            mIVIcon.setImageResource(R.mipmap.recorder);
            mIVVoiceLevel.setVisibility(View.VISIBLE);
            mTVLabel.setText("手指上滑 取消发送");
        }
    }

    public void cancelRecorder(){
        if(isShowing()){
            mIVIcon.setImageResource(R.mipmap.cancel);
            mIVVoiceLevel.setVisibility(View.GONE);
            mTVLabel.setText("手指松开 取消发送");
        }
    }

    public void tooShort(){
        if(isShowing()){
            mIVIcon.setImageResource(R.mipmap.voice_to_short);
            mIVVoiceLevel.setVisibility(View.GONE);
            mTVLabel.setText("录音时间过短");
        }
    }

    public void setVoiceLevel(int level){
        if(isShowing()){
            int resId = getContext().getResources().getIdentifier("v"+level, "mipmap", getContext().getPackageName());
            mIVVoiceLevel.setImageResource(resId);
        }
    }
}
